﻿using System;
using System.Windows;
using SoftSource.Timecard.Entry.Views;
using SoftSource.Timecard.Web.Data;

namespace SoftSource.Timecard.Entry.Controller
{
    public sealed partial class DefaultController : IController
    {
        #region IControllerBase Members

        public void DisplayError(Exception exception)
        {
            ErrorWindow.CreateNew(exception);
        }

        #endregion

        #region Views
        public Func<UIElement> CreateMainView
        {
            get
            {
                return () =>
                    {
                        FrameworkElement view = new MainView();

                        view.DataContext = DefaultController.CreateMainViewModel();

                        return view;
                    };
            }
        }

        public Func<UIElement> CreateSummaryView
        {
            get
            {
                return () =>
                {
                    FrameworkElement view = new SummaryView();

                    view.DataContext = DefaultController.CreateSummaryViewModel();

                    return view;
                };
            }
        }

        public Func<UIElement> CreateEntryView
        {
            get
            {
                return () =>
                {
                    FrameworkElement view = new EntryView();

                    view.DataContext = DefaultController.CreateEntryViewModel();

                    return view;
                };
            }
        }

        public Func<EntryLog, Action<EntryLog>, Action, UIElement> CreateEntryEditorView
        {
            get
            {
                return (entry, saveAction, completed) =>
                {
                    FrameworkElement view = new EntryEditorView();

                    view.DataContext = DefaultController.CreateEntryEditorViewModel(entry, saveAction, completed);

                    return view;
                };
            }
        }
        #endregion Views
    }
}
